import { Body, Controller, Post, HttpStatus } from '@nestjs/common';
import { ApiOperation, ApiTags, ApiResponse, ApiBearerAuth } from '@nestjs/swagger';
import { FeedbackService } from '~/modules/feedback/feedback.service';
import { CreateFeedbackDto } from '~/modules/feedback/dto/create-feedback.dto';
import { FeedbackResponseDto } from '~/modules/feedback/dto/feedback-response.dto';
import { AuthUser } from '~/modules/auth/decorators/auth-user.decorator';
import { AllowAnon } from '~/modules/auth/decorators/allow-anon.decorator';
import { ModuleSwaggerTags } from '~/constants/modules.constant';

@ApiBearerAuth()
@ApiTags(ModuleSwaggerTags.FEEDBACK)
@Controller('feedback')
export class MiniappFeedbackController {
  constructor(
    private readonly feedbackService: FeedbackService,
  ) {}

  @AllowAnon()
  @ApiOperation({ summary: '提交反馈' })
  @ApiResponse({
    status: HttpStatus.CREATED,
    description: '反馈提交成功',
    type: FeedbackResponseDto,
  })
  @Post()
  async createFeedback(
    @Body() createFeedbackDto: CreateFeedbackDto,
    @AuthUser() user: IAuthUser,
  ): Promise<FeedbackResponseDto> {
    const feedback = await this.feedbackService.saveFeedback(createFeedbackDto, user?.uid);

    return {
      id: feedback.id,
      content: feedback.content,
      type: feedback.type,
      status: feedback.status,
      userId: feedback.userId,
      createdAt: feedback.createdAt,
      updatedAt: feedback.updatedAt,
    };
  }
}
